﻿@using StudentManagement.Extensions.Pagenation;
@model PagedData<Student>

<div class="table-responsive-sm">
    <table class="table table-bordered table-hover">
        <thead>
            <tr>
                <th scope="col" class="sort-highlight">Id</th>
                <th scope="col" class="sort-highlight">
                    <a asp-action="Index"
                       asp-route-sortby="Name desc"
                       asp-route-searchString="@ViewBag.SearchString">
                        姓名
                    </a>
                </th>
                <th>
                    <a asp-action="Index"
                       asp-route-sortby="Major desc"
                       asp-route-searchString="@ViewBag.SearchString">
                        专业
                    </a>
                </th>
                <th>
                    <a asp-action="Index"
                       asp-route-sortby="Email desc"
                       asp-route-searchString="@ViewBag.SearchString">
                        电子邮箱
                    </a>
                </th>
                <th scope="col">入学日期</th>
                <th>操作</th>
            </tr>
        </thead>

        @if (Model.DataSource.Any()) {
            <tbody>
                @foreach (var student in Model.DataSource) {
                    <tr>
                        <td>@student.Id</td>
                        <td>@student.Name</td>
                        <td>@student.Major</td>
                        <td>@student.Email</td>
                        <td> @student.EnrollmentDate.ToString("yyyy-MM-dd")</td>
                        <td>
                            <a class="btn btn-primary btn-sm" asp-action="details" asp-route-id="@student.Id">浏览</a>
                            <a onclick="showInPopup('@Url.Action("AddOrEdit","Student",new {id=student.Id}, Context.Request.Scheme)','修改学生数据')"
                               class="btn btn-primary btn-sm">编辑</a>
                            <form asp-action="Delete" asp-route-id="@student.Id" 
                                  onsubmit="return doDelete(this)" class="d-inline">
                                <input type="hidden" asp-for="@student.Id" />
                                <input type="submit" value="删除" class="btn btn-danger btn-sm" />
                            </form>
                        </td>
                    </tr>
                }
            </tbody>
        }
    </table>

    @await Html.PartialAsync("_Pagination")
</div>
